<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        :focus {
            outline: none;
        }

        .box {
            width: 400px;
            height: 32px;
            background-color: aqua;
            position: relative;
        }

        .box input {
            width: 100%;
            height: 100%;
            border: 1px solid #333;
            box-sizing: border-box;
            padding-left: 10px;


        }

        .box img {
            position: absolute;
            right: 10px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="password" id="pwd">
        <img src="./images/close.png" alt="">
    </div>
    <script>

        //    var img= document.querySelector('img');
        //   var url= img.src;
        //     console.log(url);
        //     img.onclick=function(){
        //         if(this.src==url){
        //              // 图片换路径
        //         this.src='./images/open.png';
        //         }else{
        //             this.src='./images/close.png';
        //         }
        //     }



        // var img= document.querySelector('img');
        // img.onclick=function(){
        //     if(this.src.indexOf('close.png')!=-1){
        //          // 图片换路径
        //     this.src='./images/open.png';
        //     }else{
        //         this.src='./images/close.png';
        //     }
        // }

        //  开关   换标识
        var img = document.querySelector('img');
        var ipt = document.querySelector('input')
        var flag = 1;
        img.onclick = function () {
            if (flag) {
                // 图片换路径
                this.src = './images/open.png';
                // type 类型
                ipt.type = 'text'

                flag = 0;
            } else {
                this.src = './images/close.png';
                ipt.type = 'password'
                flag = 1;
            }
        }



    </script>


</body>

</html>